package com.ql.controller;

import com.ql.domain.Device;
import com.ql.domain.request.PermissionQuery;
import com.ql.domain.response.JsonResult;
import com.ql.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/deviceManage")
public class DeviceManageController {
    @Autowired
    DeviceService deviceService;

    @RequestMapping("/findAll.do")
    @ResponseBody
    public JsonResult findAll(PermissionQuery permissionQuery, String devNum, @RequestParam(name = "page", required = true, defaultValue = "1") Integer page, @RequestParam(name = "limit", required = true, defaultValue = "10") Integer limit) {
        return deviceService.findAll(permissionQuery, devNum, page, limit);
    }

    @RequestMapping("/save.do")
    @ResponseBody
    public JsonResult save(Device device) {
        return deviceService.save(device);
    }

    @RequestMapping("/update.do")
    @ResponseBody
    public JsonResult update(Device device) {
        return deviceService.update(device);
    }


    @RequestMapping("/del.do")
    @ResponseBody
    public JsonResult del(String id) {
        return deviceService.del(id);
    }

    @RequestMapping("/deviceList.do")
    @ResponseBody
    public List<Device> getDeviceList(PermissionQuery permissionQuery) {
        return deviceService.getDeviceList(permissionQuery);
    }
}
